import torch
import torch.nn as nn
import pandas as pd
import bpUtils_sse
from env import Creator
creator = Creator() #不用初始化,只调用方法，属于方法工具类，因为是类，所以需要创建实例
_, _, _, car_list_actual = creator.car_list_create()


if __name__ == '__main__':
    #拿到装载序列后做序列分析
    #序列文件
    orders = pd.read_csv("dim_4_data/PG_4Dim_3DBin_actual20230516050806Best_Order.csv") #
    #GRU: PG_4Dim_3DBin_actual20230427160816Best_Order.csv
    #Ours: PG_4Dim_3DBin_actual20230427030544Best_Order.csv
    #LSTM: PG_4Dim_3DBin_actual20230428131728Best_Order.csv
    #Linear: PG_4Dim_3DBin_actual20230428142515Best_Order.csv Gen:goods_data_profit_actual.pt
    #CNN: PG_4Dim_3DBin_actual20230509104243Best_Order.csv
    #Task 2 _Transformer: PG_4Dim_3DBin_actual20230506064835Best_Order.csv
    #Task 3 Transformer:
    #零均值归一化：Transformer ： PG_4Dim_3DBin_actual20230515134927Best_Order.csv
    #零均值归一化：Transformer ： PG_4Dim_3DBin_actual20230515165715Best_Order.csv --->min/max=81.15% 0.0006
    #零均值归一化：Transformer ： PG_4Dim_3DBin_actual20230516050806Best_Order.csv  --->min/max=79.02% 0.0005
    order_numpy = orders['Best_Order'].values
    #print(type(order_tensor.values))
    order_tensor = torch.tensor(order_numpy)
    #货物文件
    file_name = 'goods_data_profit_actual.pt'
    items = torch.load(file_name)
    zeros_count = torch.zeros(4)
    for i in items:
        if i[0][5] == 1:
            zeros_count[0]+=1
        if i[0][5] == 2:
            zeros_count[1] += 1
        if i[0][5] == 3:
            zeros_count[2] += 1
        if i[0][5] == 4:
            zeros_count[3] += 1
    print(zeros_count)
    #装箱
    avg_rate, items_list, rate_list, income_list, fl_sum_list = bpUtils_sse.calculate_rate_drl_in_detail_family_orderAnalysis(car_list_actual, items.squeeze(1), torch.tensor(order_numpy).unsqueeze(1))
    #

    for i in fl_sum_list:
        print(i)
    sum_ = torch.zeros((len(items_list)))
    for i in range(len(income_list)):
        for j in income_list[i]:
            sum_[i] += j
    msse = bpUtils_sse.sse_computer(income_list)
    print("income sum:", sum_)
    print("msse:", msse)
    #绘制装载图像
    print("图像生成中。。。")
    bpUtils_sse.draw_all_car_and_save_4ClassColor(car_list_actual,items, order_tensor)
    print("图像生成完成。。。")




